package com.wcy.controller;

import com.wcy.util.FileUploadUtil;
import com.wcy.util.vo.FileAttribute;
import jakarta.annotation.Resource;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RequestMapping("/file")
@RestController
public class FileController {
    @Resource
    private FileUploadUtil fileUploadUtil;

    @PostMapping(value="/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public FileAttribute upload(MultipartFile file) {
        System.out.println("upload:"+file.getOriginalFilename());
        return fileUploadUtil.upload(file);
    }

    @GetMapping("download/{convertedFileName}")
    public ResponseEntity<byte[]> download(@PathVariable("convertedFileName") String convertedFileName) {
        return fileUploadUtil.download(convertedFileName);
    }
}
